<?php
/**
 * Created by PhpStorm.
 * User: coolinmind
 * Date: 28/02/2019
 * Time: 11:18
 */

namespace App\Modules\UCenter;


use App\Services\Integral\IntegralIndex;

class Integral extends BaseUcenter
{
    /*----------------------------------------前台-----------------------------------------------------------*/

    /*积分操作（增加）（接单成功奖励等）*/
    public function addIntegral(): array
    {
        $res = $this->isLogin();
        if ($res['status'] !== SUCCESS_STATUS) {
            return need_login($res,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $res['res']['id'];
        return IntegralIndex::Integral()->addIntegral($data);
    }
    /*用户积分详情*/
    public function integralInfo(): array
    {
        $res = $this->isLogin();
        if ($res['status'] !== SUCCESS_STATUS) {
            return need_login($res,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $res['res']['id'];
        return IntegralIndex::Integral()->integralInfo($data);
    }
    /*用户积分记录*/
    public function integralList(): array
    {
        $res = $this->isLogin();
        if ($res['status'] !== SUCCESS_STATUS) {
            return need_login($res,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $res['res']['id'];
        return IntegralIndex::Integral()->integralList($data);
    }
    /*兑换*/
    public function addOrder(): array
    {
        $res = $this->isLogin();
        if ($res['status'] !== SUCCESS_STATUS) {
            return need_login($res,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $res['res']['id'];
        return IntegralIndex::Integral()->addOrder($data);
    }
    /*兑换记录列表*/
    public function orderList(): array
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return IntegralIndex::Integral()->orderList($data);
    }
    /*----------------------------------------后台-----------------------------------------------------------*/
    /*用户积分列表 可查用户*/
    public function adminIntegralList(): array
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return IntegralIndex::Integral()->adminIntegralList($data);
    }
    /*积分操作记录 可查用户*/
    public function adminOptionLog(): array
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return IntegralIndex::Integral()->adminOptionLog($data);
    }

    /*用户兑换记录列表 可查用户*/
    public function adminOrderList(): array
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return IntegralIndex::Integral()->adminOrderList($data);
    }

    /*发货*/
    public function deliverGoods(): array
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return IntegralIndex::Integral()->deliverGoods($data);
    }

}
